#include "dxstdafx.h"
#include "Log.h"
#include "fstream"
using namespace std;

CLog::CLog(void)
{
}

CLog::~CLog(void)
{
}

void CLog::BeginRoll(Cube* pCube)
{
    CubeStatus* pStatus = pCube->GetStatus(); 
    WriteStatus(pStatus);
}
void CLog::EndRoll(Cube* pCube)
{
    CubeStatus* pStatus = pCube->GetStatus(); 
    WriteStatus(pStatus);
}
void CLog::WriteStatus(CubeStatus* cubeStatus)
{
    ofstream out;
    out.open("log.txt", ios::app);

    string s_Color[] = {"Yellow", "White ", "Red   ", "Green ", "Orange", "Blue  ", "Null  "};
    string s_Faces[] = {"U", "D", "F", "R", "B", "L", "*"};
    string s_Blank   =  "          ";
    string strLog;

    CubeFace* pColor = cubeStatus->GetState(); 
    for (int i = 0; i < faceNull; ++i)
    {            
        string strFace  = s_Faces[pColor[i]];
        if (0 == strcmp(s_Faces[pColor[i]].c_str(), s_Faces[6].c_str()))
        {
            strLog += s_Blank;
            continue;
        }
        strLog += "[";
        strLog += strFace;
        strLog += "]";
        string strColor = s_Color[i];
        strLog += strColor;
        strLog += " ";
    }
    strLog += "\n";
    out << strLog.c_str();

    out.close();
}